<template>

<page-view class="main">
 
     <router-view v-slot="{Component}"> 
       <transition :name="animation">
        <keep-alive>
          <component :is="Component"></component>
        </keep-alive>
       </transition>
     </router-view>

<div class="footer">
  <router-link to="/main/menu">
      <div class="iconfont icon-diancan"></div>
      <h3>点餐</h3>
    </router-link> 
    <router-link to="/main/menu">
      <div class="iconfont icon-diancan"></div>
      <h3>点餐</h3>
    </router-link> 
    <router-link to="/main/menu">
      <div class="iconfont icon-diancan"></div>
      <h3>点餐</h3>
    </router-link> 
    <router-link to="/main/menu">
      <div class="iconfont icon-diancan"></div>
      <h3>点餐</h3>
    </router-link> 

</div>
    
    

</page-view>
</template>

<script>
import {ref, watch} from 'vue'
import { useRoute } from 'vue-router'
import PageView from '../components/PageView.vue'
export default{
  components: { PageView },
name:'Main',
setup(){
  let animation=ref('slide')
  const route=useRoute()

  let routeIndex=route.meta.index

  watch(route,()=>{
    animation.value= route.meta.index<routeIndex?'slide-right':'slide-left'
     routeIndex=route.meta.index
  })

  return {animation}

}

}

</script>

<style lang="scss">
.main{
  width:100vw ;
  height: 100vh;
  overflow: hidden;
}

//向左
.slide-left-enter-from{
  transform: translateX(100%);
}

.slide-left-enter-to,.slide-left-leave-from,.slide-left-leave-to{
  transform: translateX(0%);
}

.slide-left-enter-active,.slide-left-leave-active{
  transition: all 200ms linear;
  position: fixed;
}
//向右
.slide-right-enter-from{
  transform: translateX(-100%);
}
.slide-right-enter-to,.slide-right-leave-from,.slide-right-leave-to{
  transform: translateX(0%);
}

.slide-right-enter-active,.slide-right-leave-active{
  transition: all 200ms linear;
  position: fixed;
}


</style>
